Exotica

This section describes some low-level routines that are sometimes useful in mucking around with buffers. These are for serious hackers only.

$alloc_buff(Size,Buff,Type,Supbuff,Retcode)
$alloc_buff/5 (L) Allocates a buffer. Size is the length (in bytes) of the buffer to allocate; Buff is the buffer allocated, and should be unbound at the time of the call; Type indicates where to allocate the buffer: a value of 0 indicates that the buffer is to be allocated in permanent space, 1 that it should be on the heap, and 2 indicates that it should be allocated from a larger heap buffer; Supbuff is the larger buffer to allocate a subbuffer out of, and is only looked at if the value of Type is 2; Retcode is the return code: a value of 0 indicates that the buffer has been allocated, while a value of 1 indicates that the buffer could not be allocated due to lack of space. The arguments Size, Type, and Supbuff (if $\em Type$ = 2) are input arguments, and should be bound at the time of the call; Buff and Retcode are output arguments, and should be unbound at the time of the call.

call_ref(Call, Ref)
call_ref/2 (L) Calls the predicate whose database reference (prref) is Ref, using the literal Call as the call. This is similar to call_ref(Call, Ref, 0).

call_ref(Call, Ref, Tr)
call_ref/3 (L) Calls the predicate whose database reference (prref) is Ref, using the literal Call as the call. Tr must be either 0 or 1: if Tr is 0 then the call Call is made assuming the ``trust'' optimization will be made; if Tr is 1 then the ``trust'' optimization is not used, so that any new fact added before final failure will be seen by Call. (Also, this currently does not take advantage of any indexing that might have been constructed.) Call, Ref and Tr are all input arguments, and should be instantiated at the time of call.

$assertf_alloc_t(Palist,Size)
$assertf_alloc_t (L) Declares that each predicate in the list Palist of predicate/arity pairs (terms of the form `/'(P,N) where P is a predicate symbol and N the arity of P) is to have any facts asserted to them stored in a buffer on the heap, to be allocated here. This allocates a superbuffer of size Size on the heap. Future assertions to these predicates will have their clauses put in this buffer. When this call is backtracked over, any clauses asserted to these predicates are deallocated, and a subsequent call to any of those predicates will cause the simulator to report an error and fail. Both Palist and Size are input arguments, and should be instantiated at the time of call.

$db_new_prref(Prref,Where,Supbuff)
$db_new_prref/3 (L) Creates an empty Prref, i.e. one with no facts in it. If called, it will simply fail. Where indicates where the prref should be allocated: a value of 0 indicates the permanent area, while a value of 2 indicates that it is to be allocated as a subbuffer. Supbuff is the superbuffer from which to allocate Prref if Where is 2. Where should be instantiated at the time of call, while Prref should be uninstantiated; in addition, if Where is 2, Supbuff should be instantiated at the time of call.

$db_assert_fact(Fact,Prref,AZ,Index,Clref,Where,Supbuff)
$db_assert_fact/5 (L) Fact is a fact to be asserted; Prref is a predicate reference to which to add the asserted fact; AZ is either 0, indicating the fact should be inserted as the first clause in Prref, or 1, indicating it should be inserted as the last; Index is 0 if no index is to be built, or n if an index on the n$\scriptstyle \em th$ argument of the fact is to be used. (Asserting at the beginning of the chain with indexing is not yet supported.) Where indicates where the clref is to be allocated: a value of 0 indicates that it should be in the permanent area, while a value of 2 indicates that it should be allocated as a subbuffer of Supbuff. Clref is returned and it is the clause reference of the asserted fact. Fact, Prref, AZ, Index, and Where are input arguments, and should be instantiated at the time of call; in addition, if Where is 2, then Supbuff should also be instantiated. Clref is an output argument, and should be uninstantiated at the time of call.

$db_add_clref(Fact,Prref,AZ,Index,Clref,Where,Supbuff)
$db_add_clref/7 (L) Adds the clref Clref to the prref Prref. Fact is the fact that has been compiled into Clref (used only to get the arity and for indexing). The other parameters are as for $db_assert_fact/7.

$db_call_prref(Call,Prref)
$db_call_prref/2 (L) Calls the prref Prref using the literal Call as the call. The call is done by simply branching to the first clause. New facts added to Prref after the last fact has been retrieved by Call, but before Call is failed through, will not be used. Both Call and Prref are input arguments, and should be instantiated at the time of call.

$db_call_prref_s(Call,Prref)
$db_call_prref_s/2 (L) This also calls the prref Prref using Call as the call. The difference from $db_call_prref is that this does not use the ``trust'' optimization, so that any new fact added before final failure will be seen by Call. (Also, this currently does not take advantage of any indexing that might have been constructed, while $db_call_prref does.) Both Call and Prref are input arguments, and should be instantiated at the time of call.

$db_get_clauses(Prref,Clref,Dir)
$db_get_clauses/3 (L) This returns, nondeterministically, all the clause references Clref for clauses asserted to prref Prref. If Dir is 0, then the first clref on the list is returned first; if Dir is 1, then they are returned in reverse order. Prref and Dir are input arguments, and should be instantiated at the time of call; Clref is an output argument, and should be uninstantiated at the time of call.